from api_test.api.calendar.calendar_api import CalendarApi
from api_test.api.calendar.event_api import EventApi
from api_test.testcases.base_feishu_testcase import BaseFeiShuTestCase


class BaseEventTestCase(BaseFeiShuTestCase):
    def setup_class(self):
        self.eventapi = EventApi()
        self.calendarapi = CalendarApi()

    def teardown_class(self):
        print("\nteardown_class")
        print(self.calendarapi.calendar_ids, self.eventapi.event_ids)
        for cid in self.calendarapi.calendar_ids:
            for eid in self.eventapi.event_ids:
                res = self.eventapi.delete(cid, eid)
                if res.get('code') != 0:
                    if res.get('code') != 193003:
                        print(f"\n{eid} 删除失败 {res}")
                        return f"\n{eid} 删除失败 {res}"
            res = self.calendarapi.delete(cid)
            print(f"calendarapi.delete: {res}")
            if res.get('code') != 0:
                if res.get('code') != 191003:
                    print(f"\n{cid} 删除失败 {res}")
                    return f"\n{cid} 删除失败 {res}"
        print("\n数据后置OK! ")